public class Solution925 {
    public boolean isLongPressedName(String name, String typed) {
        int i=0,j=0;
        while (i<name.length()){
            if (j==typed.length()){
                return false;
            }
            if (i<name.length()-1 && name.charAt(i)!=name.charAt(i+1) || i==name.length()-1){
                int last=j;
                while (j<typed.length() && typed.charAt(j)==name.charAt(i)){
                    j++;
                }
                if (last==j){
                    return false;
                }
            }else{
                if (name.charAt(i)!=typed.charAt(j)){
                    return false;
                }
                j++;
            }
            i++;
        }
        return j==typed.length();
    }

    public static void main(String[] args) {
        System.out.println(new Solution925().isLongPressedName("alex","aaleex"));
    }
}
